

public class CharacterCount {

    public static void main(String[] args) {
        int count = sameCountCheck("Mississippi", 's');
        System.out.println("Counting the number of occurrence of 's' in \"Mississippi\" is " + count);
    }

    public static int sameCountCheck(String message, char checkCharacter) {
        if (message == null || message.isEmpty()) {
            return 0;
        }

        return sameCountCheckRecursive(message.toUpperCase(), Character.toUpperCase(checkCharacter), 0, 0);
    }

    public static int sameCountCheckRecursive(String message, char checkCharacter, int charIndex, int count) {
        if (message.length() <= charIndex) {
            return count;
        } else if (message.charAt(charIndex) == checkCharacter) {
            count += 1;
        }

        return sameCountCheckRecursive(message, checkCharacter, charIndex + 1, count);
    }

}
